﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using MediSIIM.DBAccess;
using System.Runtime.InteropServices;

namespace SIIMWeb.YIBAO
{
    public class DBUtil
    {
        [DllImport("Project1.dll", CharSet = CharSet.Ansi)]
        public static extern int TransactionApply2(string x, ref string y);
        public static DBConnectionManager ConnectionManager { get; set; }
        static DBUtil()
        {
            ConnectionManager = new DBConnectionManager();
            CreateDBConnection();
        }
        public static void CreateDBConnection()
        {
            int count = ConfigurationManager.ConnectionStrings.Count;
            for (int i = 0; i < count; i++)
            {
                if (ConfigurationManager.ConnectionStrings[i].Name.Contains("LocalSql") || ConfigurationManager.ConnectionStrings[i].Name.Contains("OraAspNetConString"))
                {
                    continue;
                }

                DBConfig dbConfig = new DBConfig();
                dbConfig.ConnectionName = ConfigurationManager.ConnectionStrings[i].Name;
                dbConfig.ConnectionString = ConfigurationManager.ConnectionStrings[i].ConnectionString;
                dbConfig.ProviderName = ConfigurationManager.ConnectionStrings[i].ProviderName;
                dbConfig.DBType = DataBaseType.ORACLE;

                DBConnection dbconn = new DBConnection();

                dbconn.DBFactory = DataAccess.GetDbFactory(dbConfig);
                dbconn.Instance = DataAccess.CreateConnection(dbConfig);

                ConnectionManager.AddConnection(dbConfig.ConnectionName, dbconn);
            }
        }
    }
}
